package Thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-07-31
 * Time: 21:24
 */
public class demo17 {
    private static Object A = new Object();
    private static Object B = new Object();

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            synchronized (A) {
                System.out.println("线程1对A进行加锁成功");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (B) {
                    System.out.println("线程1对B进行加锁");
                }
            }
        });
        Thread t2 = new Thread(() -> {
            synchronized (A) {
                System.out.println("线程2对A进行加锁成功");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (B) {
                    System.out.println("线程2对B进行加锁");
                }
            }
        });

        t1.start();
        t2.start();
    }
}
